package com.sfh.gd.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
 * 如
 * {"data":这里是你要返回的数据类型,
 * "status":1,
 * "successed": true,
 * "message":"操作成功"}
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private int errorCode;
    private T data;
    private String errorMessage;

    public static <T> Result<T> success(T data) {
        return new Result<T>(0,  data,"");
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<T>(-1,null,msg);
    }
    public static <T> Result<T> fail(int errorCode,String msg) {
        return new Result<T>(errorCode, null,msg);
    }
//    /**
//     * 构建服务端失败响应
//     */
//    public static Result<Void> failure() {
//        return Result.create(BaseErrorCode.SERVICE_ERROR.code(),BaseErrorCode.SERVICE_ERROR.message());
//    }
//
//    /**
//     * 通过 {@link AbstractException} 构建失败响应
//     */
//    public static Result failure(AbstractException abstractException) {
//        String errorCode = Optional.ofNullable(abstractException.getErrorCode())
//                .orElse(BaseErrorCode.SERVICE_ERROR.code());
//        String errorMessage = Optional.ofNullable(abstractException.getErrorMessage())
//                .orElse(BaseErrorCode.SERVICE_ERROR.message());
//        return Result.create(errorCode,errorMessage);
//    }
//
//    /**
//     * 通过 errorCode、errorMessage 构建失败响应
//     */
//    public static Result<Void> failure(String errorCode, String errorMessage) {
//        return Result.create(errorCode,errorMessage);
//    }
}

